from django.db import models


# Create your models here.

class BookInfoManage(models.Manager):
    # def create_book(self, title, pub_date):
    #     book = self.model()
    #     book.btitle = title
    #     book.bpub_date = pub_date
    #     book.isDelete = False
    #     book.bread = 0
    #     book.bcommet = 0
    #     return book

    def create_book(self, title, pub_date):
        return self.create(btitle=title, bpub_date=pub_date, isDelete=0, bread=0, bcommet=0)


class BookInfo(models.Model):
    btitle = models.CharField(max_length=20)
    bpub_date = models.DateTimeField()
    bread = models.IntegerField(default=0)
    bcommet = models.IntegerField(default=0)
    isDelete = models.BooleanField(default=False)

    # books = BookInfoManage()

    class Meta():
        ordering = ['-id']

    def __str__(self):
        return self.btitle


class HeroInfo(models.Model):
    hname = models.CharField(max_length=20)
    hgender = models.BooleanField(default=True)
    hcontent = models.CharField(max_length=1000)
    isDelete = models.BooleanField(default=False)
    hBook = models.ForeignKey('BookInfo')

    def gender(self):
        if self.hgender:
            return '男'
        else:
            return '女'

    gender.short_description = '性别'  # 重定义字段显示名称,但是非数字段似乎不生效


    # def __str__(self):
    #     return "Hero{hname:%s,hgender:%s,gender:%s,hBook:%s" % (self.hname, self.gender, self.hcontent, self.hBook)


class AreaInfo(models.Model):
    atitle = models.CharField(max_length=20)
    aParent = models.ForeignKey('self', null=True, blank=True)

    def __str__(self):
        return self.atitle
